﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for clsLoadCombobox
/// </summary>
public class clsLoadCombobox
{
    SoLienLacDataContext db = new SoLienLacDataContext();
	public clsLoadCombobox()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public void LoadComboboxNamHoc(DropDownList ddl)
    {
        var c = from i in
                    (from p in db.Lop_HocSinhs select new { p.MaNam, p.NamHoc.TenNam })
                group i by new { i.MaNam, i.TenNam } into grp
                select new { grp.Key.MaNam,grp.Key.TenNam};
        ddl.DataTextField = "TenNam";
        ddl.DataValueField = "MaNam";
        ddl.DataSource = c;
        ddl.DataBind();
    }
    public void LoadComboKhoi(DropDownList dr)
    {
        var c = from p in db.KhoiHocs select new { p.MaKhoi,p.TenKhoi };
        dr.DataTextField = "TenKhoi";
        dr.DataValueField = "MaKhoi";
        dr.DataSource = c;
        dr.DataBind();

    }
    public void LoadComboboxNamHoc2(DropDownList drp)
    {
        var c =from p in db.NamHocs select p;
               
        drp.DataTextField = "TenNam";
        drp.DataValueField = "MaNam";
        drp.DataSource = c;
        drp.DataBind();
    }
    public void LoadComboboxKhoi(DropDownList drp)
    {
        var c = from p in db.KhoiHocs select p;
        drp.DataTextField = "TenKhoi";
        drp.DataValueField = "MaKhoi";
        drp.DataSource = c;
        drp.DataBind();
    }
    public void LoadComboboxLopTheoKhoi(DropDownList drp,int makhoi)
    {
        var c = from p in db.LopHocs where p.MaKhoi == makhoi select new { p.MaLop,p.TenLop };
        drp.DataTextField = "TenLop";
        drp.DataValueField = "MaLop";
        drp.DataSource = c;
        drp.DataBind();
    }
    public void LoadComboboxLopHocTheoMaGV(DropDownList ddl, int manam,string magv)
    {
        var c = from p in db.Lop_Bans where p.MaNam == manam && p.MaCanBoGV == magv select new { p.MaLop, p.LopHoc.TenLop };
               
        ddl.DataTextField = "TenLop";
        ddl.DataValueField = "MaLop";
        ddl.DataSource = c;
        ddl.DataBind();
    }
    public void LoadComboboxLopHoc(DropDownList ddl,int manam)
    {
        var c = from i in
                    (from p in db.Lop_HocSinhs where p.MaNam==manam select new { p.MaLop, p.LopHoc.TenLop })
                group i by new { i.MaLop, i.TenLop } into grp
                select new { grp.Key.MaLop,grp.Key.TenLop};
        ddl.DataTextField = "TenLop";
        ddl.DataValueField = "MaLop";
        ddl.DataSource = c;
        ddl.DataBind();
    }
    public void LoadComboboxMonHoc(DropDownList ddl, int malop, int manam)
    {
        var c = from p in db.Lop_Bans
                where p.MaNam == manam && p.MaLop == malop
                select p.MaBan ;
        var c1 = from p in db.BanHoc_MonHocs where p.MaBan==int.Parse(c.ToString()) select new { p.MaMon, p.MonHoc.TenMon};
        ddl.DataTextField = "TenMon";
        ddl.DataValueField = "MaMon";
        ddl.DataSource = c1;
        ddl.DataBind();
    }
    public void LoadComboboxMonHocTheoMaGV(DropDownList ddl,int malop, int manam,string magv)
    {
        var c = from p in db.GiaoVien_Lop_Mons
                where p.MaNam == manam && p.MaLop == malop && p.MaCanBoGV==magv
                select new {p.MaMon,p.MonHoc.TenMon};
        //var c1 = from p in db.BanHoc_MonHocs where p.MaBan==int.Parse(c.ToString()) select new { p.MaMon, p.MonHoc.TenMon};
        ddl.DataTextField = "TenMon";
        ddl.DataValueField = "MaMon";
        ddl.DataSource = c;
        ddl.DataBind();
    }
    public void LoadCBMon(DropDownList ddl)
    {
        var c = from p in db.MonHocs
                select new { p.MaMon, p.TenMon };
        ddl.DataTextField = "TenMon";
        ddl.DataValueField = "MaMon";
        ddl.DataSource = c;
        ddl.DataBind();
    }
    public void LoadComboboxLoaiDiem(DropDownList ddl)
    {
        ddl.Items.Add("Điểm miệng");
        ddl.Items.Add("Điểm 15p");
        ddl.Items.Add("Điểm 45p");
        ddl.Items.Add("Điểm thi");
    }
    public void LoadComLoiVP(DropDownList dr)
    {
        var c = from p in db.LoiViPhams
                where p.TenLoiVP != "Nghỉ học có phép" && p.TenLoiVP != "Nghỉ học không phép"
                select new { p.MaLoiVP,p.TenLoiVP};
        dr.DataTextField = "TenLoiVP";
        dr.DataValueField = "MaLoiVP";
        dr.DataSource = c;
        dr.DataBind();
    }

}
